package co.fitstart.weapp.api.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.content.Activity;
import co.fitstart.entity.content.Article;
import co.fitstart.entity.content.Module;
import co.fitstart.entity.content.Status;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface ContentDao {
    
    /**
     * 
     * @param status
     * @param name
     * @return
     */
    @Query("SELECT COUNT(*) FROM Activity WHERE disabled = false AND status = :status AND name LIKE :name ORDER BY endDate DESC, serial DESC")
    public int countActivity(@Variable("status") Status status, @Variable("name") String name);

    /**
     * 
     * @param status
     * @return
     */
    @Query("SELECT COUNT(*) FROM Activity WHERE disabled = false AND status = :status ORDER BY endDate DESC, serial DESC")
    public int countActivity(@Variable("status") Status status);

    
    /**
     * 
     * @param status
     * @param name
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Activity WHERE disabled = false AND status = :status AND name LIKE :name ORDER BY endDate DESC, serial DESC")
    public List<Activity> listActivity(@Variable("status") Status status, @Variable("name") String name, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    
    /**
     * 
     * @param status
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Activity WHERE disabled = false AND status = :status ORDER BY endDate DESC, serial DESC")
    public List<Activity> listActivity(@Variable("status") Status status, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);

    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Article WHERE disabled = false ORDER BY createTime DESC")
    public List<Article> listArticle(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @return
     */
    @Query("FROM Module WHERE disabled = false AND display = true")
    public List<Module> listModule();
    
    /**
     * 
     * @param id
     * @return
     */
    @Query("FROM Module WHERE id = :id AND disabled = false AND display = true")
    public Module loadModule(@Variable("id") Long id);

}
